package cn.lutu.domain.repository.impl;

import cn.lutu.dao.mapper.HotelsMapper;
import cn.lutu.dao.mapper.RoomMapper;
import cn.lutu.domain.repository.HotelRepository;
import cn.lutu.protocol.entity.Hotel;
import cn.lutu.protocol.search.ArticleSearchVO;
import cn.lutu.protocol.vo.HotelVO;
import cn.lutu.protocol.vo.RoomVO;
import cn.lutu.util.common.PageInfoToPageDataConverter;
import cn.lutu.util.pojo.vo.PageData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class HotelRepositoryImpl implements HotelRepository {

    @Autowired
    HotelsMapper hotelsMapper;

    @Autowired
    RoomMapper roomMapper;

    @Override
    public void updateById(Hotel hotel) {
        hotelsMapper.updateById(hotel);
    }

    @Override
    public void insertRoom(Hotel hotel) {

    }

    @Override
    public void updateRoom(Hotel hotel) {

    }

    @Override
    public void deleteById(Long id) {

    }

    @Override
    public void deleteHotelById(Long id) {
        roomMapper.deleteById(id);
    }

    @Override
    public HotelVO selectHotel(Long id) {
        return null;
    }

    @Override
    public void insert(Hotel hotel) {
        hotelsMapper.insert(hotel);
    }

    @Override
    public HotelVO selectRoom(Long id) {
        return null;
    }

    @Override
    public PageData<HotelVO> selectHotelList(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询酒店列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<HotelVO> list = hotelsMapper.selectHotelRoomList();
        PageInfo<HotelVO> pageInfo = new PageInfo<>(list);
        PageData<HotelVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public HotelVO selectHotelListById(Long id) {

        return hotelsMapper.selectHotelListById(id);
    }

    @Override
    public List<RoomVO> selectRoomById(Long id) {
        return hotelsMapper.selectRoomById(id);
    }

    @Override
    public List<HotelVO> selectAllHotels() {
        return hotelsMapper.selectHotelsList();
    }

    @Override
    public List<HotelVO> selectAllHotel() {
        return hotelsMapper.selectHotelList();
    }
}
